#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc,char* argv[])
{
    //计算器要4个参数，一个参数是./,两个数字，一个运算符
    if(argc != 4)
    {
        printf("Usage:\n");
        printf("     ");
        printf("./Counter sum/sub/mul/div x y\n");
        return 1;
    }
    int x = atoi(argv[2]);
    int y = atoi(argv[3]);
    if(strcmp(argv[1],"sum") == 0)
    {
        printf("sum:%d+%d=%d\n",x,y,x+y);
    }
    else if(strcmp(argv[1],"sub") == 0)
    {
        printf("sub:%d-%d=%d\n",x,y,x-y);
    }
    else if(strcmp(argv[1],"mul") == 0)
    {
        printf("mul:%d*%d=%d\n",x,y,x*y);
    }
    else if(strcmp(argv[1],"div") == 0)
    {
        if(y == 0)
        {
            printf("Error: divisor can not be zero! Please enter a new divisor\n");//除数不能为0
            return 2;
        }

        printf("div:%d/%d=%d\n",x,y,x/y);
    }
    return 0;
}
